/**
 *
 */
import OpenApi;
import OpenApi.OpenApiUtil;

extends OpenApi;


init(config: OpenApiUtil.Config){
  super(config);
  @endpointRule = 'central';
  @endpointMap = {
    'ap-northeast-1' = 'workorder.ap-northeast-1.aliyuncs.com',
    'ap-southeast-1' = 'workorder.ap-southeast-1.aliyuncs.com',
  };

  checkConfig(config);
  @endpoint = getEndpoint('workorder', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!$isNull(endpoint)) {
    return endpoint;
  }
  
  if (!$isNull(endpointMap) && !$isNull(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return OpenApiUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CategoryParam {
  categoryId?: long(name='CategoryId'),
  categoryName?: string(name='CategoryName'),
  isSelectFromDialog?: boolean(name='IsSelectFromDialog'),
  productId?: long(name='ProductId'),
  productName?: string(name='ProductName'),
}

model DialogBaseBody {
  attachments?: [ 
    {
      name?: string(name='Name'),
      size?: string(name='Size'),
      type?: string(name='Type'),
      url?: string(name='Url'),
    }
  ](name='Attachments'),
  channelCode?: string(name='ChannelCode'),
  createTime?: long(name='CreateTime'),
  dataInfo?: {
    bizId?: string(name='BizId'),
    bizType?: int32(name='BizType'),
    component?: [ map[string]any ](name='Component'),
    content?: string(name='Content'),
    contentDesensitized?: string(name='ContentDesensitized'),
    editable?: int32(name='Editable'),
    props?: [ map[string]any ](name='Props'),
    schema?: string(name='Schema'),
    schemaId?: long(name='SchemaId'),
    serviceChannel?: string(name='ServiceChannel'),
    title?: string(name='Title'),
    values?: map[string]any(name='Values'),
  }(name='DataInfo'),
  dialogId?: long(name='DialogId'),
  footerInfo?: {
    ext?: map[string]any(name='Ext'),
    schema?: string(name='Schema'),
  }(name='FooterInfo'),
  hitWords?: [ string ](name='HitWords'),
  modifiedTime?: long(name='ModifiedTime'),
  referInfo?: DialogBaseBody(name='ReferInfo'),
  stage?: int32(name='Stage'),
  status?: int32(name='Status'),
  ticketId?: string(name='TicketId'),
  ticketStatus?: int32(name='TicketStatus'),
  timestamp?: long(name='Timestamp'),
  tip?: string(name='Tip'),
  type?: int32(name='Type'),
  userInfo?: {
    avatar?: string(name='Avatar'),
    role?: int32(name='Role'),
    userId?: string(name='UserId'),
    userName?: string(name='UserName'),
  }(name='UserInfo'),
}

model GetTicketTemplateRequest {
  categoryId?: long(name='CategoryId', description='This parameter is required.'),
  cna?: string(name='Cna'),
  distributionChannel?: string(name='DistributionChannel'),
  referrer?: string(name='Referrer'),
  subDistributionChannel?: string(name='SubDistributionChannel'),
  XGatewayExtendInfo?: string(name='XGatewayExtendInfo'),
}

model GetTicketTemplateResponseBody = {
  accessDeniedDetail?: string(name='AccessDeniedDetail'),
  code?: int32(name='Code'),
  data?: map[string]any(name='Data'),
  httpStatusCode?: int32(name='HttpStatusCode'),
  message?: string(name='Message'),
  pageNumber?: int32(name='PageNumber'),
  pageSize?: int32(name='PageSize'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
  totalCount?: long(name='TotalCount'),
}

model GetTicketTemplateResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetTicketTemplateResponseBody(name='body'),
}

/**
 * @param request GetTicketTemplateRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetTicketTemplateResponse
 */
async function getTicketTemplateWithOptions(request: GetTicketTemplateRequest, runtime: $RuntimeOptions): GetTicketTemplateResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.categoryId)) {
    query['CategoryId'] = request.categoryId;
  }
  if (!$isNull(request.cna)) {
    query['Cna'] = request.cna;
  }
  if (!$isNull(request.distributionChannel)) {
    query['DistributionChannel'] = request.distributionChannel;
  }
  if (!$isNull(request.referrer)) {
    query['Referrer'] = request.referrer;
  }
  if (!$isNull(request.subDistributionChannel)) {
    query['SubDistributionChannel'] = request.subDistributionChannel;
  }
  if (!$isNull(request.XGatewayExtendInfo)) {
    query['XGatewayExtendInfo'] = request.XGatewayExtendInfo;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'GetTicketTemplate',
    version = '2020-12-10',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @param request GetTicketTemplateRequest
 * @return GetTicketTemplateResponse
 */
async function getTicketTemplate(request: GetTicketTemplateRequest): GetTicketTemplateResponse {
  var runtime = new $RuntimeOptions{};
  return getTicketTemplateWithOptions(request, runtime);
}

model IsFirstBbsTicketRequest {
  cna?: string(name='Cna'),
  distributionChannel?: string(name='DistributionChannel'),
  referrer?: string(name='Referrer'),
  subDistributionChannel?: string(name='SubDistributionChannel'),
  XGatewayExtendInfo?: string(name='XGatewayExtendInfo'),
}

model IsFirstBbsTicketResponseBody = {
  code?: string(name='Code'),
  data?: boolean(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model IsFirstBbsTicketResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: IsFirstBbsTicketResponseBody(name='body'),
}

/**
 * @summary 是否首次访问BBS工单
 *
 * @param request IsFirstBbsTicketRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return IsFirstBbsTicketResponse
 */
async function isFirstBbsTicketWithOptions(request: IsFirstBbsTicketRequest, runtime: $RuntimeOptions): IsFirstBbsTicketResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.cna)) {
    query['Cna'] = request.cna;
  }
  if (!$isNull(request.distributionChannel)) {
    query['DistributionChannel'] = request.distributionChannel;
  }
  if (!$isNull(request.referrer)) {
    query['Referrer'] = request.referrer;
  }
  if (!$isNull(request.subDistributionChannel)) {
    query['SubDistributionChannel'] = request.subDistributionChannel;
  }
  if (!$isNull(request.XGatewayExtendInfo)) {
    query['XGatewayExtendInfo'] = request.XGatewayExtendInfo;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'IsFirstBbsTicket',
    version = '2020-12-10',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @summary 是否首次访问BBS工单
 *
 * @param request IsFirstBbsTicketRequest
 * @return IsFirstBbsTicketResponse
 */
async function isFirstBbsTicket(request: IsFirstBbsTicketRequest): IsFirstBbsTicketResponse {
  var runtime = new $RuntimeOptions{};
  return isFirstBbsTicketWithOptions(request, runtime);
}

model SuggestCategoryRequest {
  cna?: string(name='Cna'),
  content?: string(name='Content'),
  distributionChannel?: string(name='DistributionChannel'),
  referrer?: string(name='Referrer'),
  subDistributionChannel?: string(name='SubDistributionChannel'),
  ticketId?: string(name='TicketId'),
  topN?: int32(name='TopN'),
  useHotSuggestCatchAll?: boolean(name='UseHotSuggestCatchAll'),
  XGatewayExtendInfo?: string(name='XGatewayExtendInfo'),
}

model SuggestCategoryResponseBody = {
  accessDeniedDetail?: string(name='AccessDeniedDetail'),
  code?: string(name='Code'),
  data?: [  map[string]any ](name='Data'),
  httpStatusCode?: int32(name='HttpStatusCode'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model SuggestCategoryResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SuggestCategoryResponseBody(name='body'),
}

/**
 * @param request SuggestCategoryRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SuggestCategoryResponse
 */
async function suggestCategoryWithOptions(request: SuggestCategoryRequest, runtime: $RuntimeOptions): SuggestCategoryResponse {
  request.validate();
  var query = {};
  if (!$isNull(request.cna)) {
    query['Cna'] = request.cna;
  }
  if (!$isNull(request.content)) {
    query['Content'] = request.content;
  }
  if (!$isNull(request.distributionChannel)) {
    query['DistributionChannel'] = request.distributionChannel;
  }
  if (!$isNull(request.referrer)) {
    query['Referrer'] = request.referrer;
  }
  if (!$isNull(request.subDistributionChannel)) {
    query['SubDistributionChannel'] = request.subDistributionChannel;
  }
  if (!$isNull(request.ticketId)) {
    query['TicketId'] = request.ticketId;
  }
  if (!$isNull(request.topN)) {
    query['TopN'] = request.topN;
  }
  if (!$isNull(request.useHotSuggestCatchAll)) {
    query['UseHotSuggestCatchAll'] = request.useHotSuggestCatchAll;
  }
  if (!$isNull(request.XGatewayExtendInfo)) {
    query['XGatewayExtendInfo'] = request.XGatewayExtendInfo;
  }
  var req = new OpenApiUtil.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApiUtil.Params{
    action = 'SuggestCategory',
    version = '2020-12-10',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  if ($isNull(@signatureVersion) || @signatureVersion != 'v4') {
    return callApi(params, req, runtime);
  } else {
    return execute(params, req, runtime);
  }
}

/**
 * @param request SuggestCategoryRequest
 * @return SuggestCategoryResponse
 */
async function suggestCategory(request: SuggestCategoryRequest): SuggestCategoryResponse {
  var runtime = new $RuntimeOptions{};
  return suggestCategoryWithOptions(request, runtime);
}

